package com.pan.old.tools;

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Paths;
import java.util.Scanner;

public class ReadFileCSV {

    String delimiter = ",";

    File file;

    Scanner scanner;

    public ReadFileCSV(String delimiter,String filePath) {
        this.delimiter = delimiter;
        try {
            this.scanner = new Scanner(new File(filePath));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public ReadFileCSV(String filePath) {
        this(",",filePath);
    }


    public String readAll(String path){
        File f = Paths.get(path).toFile();
        String result = "";
        try {
            Scanner scanner = new Scanner(f);
            while (scanner.hasNextLine()){
                result += scanner.nextLine()+"\n";
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        return result;
    }

    public String[] readNextLine(){
        if (hasNextLine()){
            return scanner.nextLine().split(delimiter);
        }else
            return null;
    }


    public boolean hasNextLine(){
        return scanner.hasNextLine();
    }


}
